import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Layout/Home'
// 路由懒加载，写成函数的格式，webpack打包的时候，看到这个表标识就不会加载这个js文件
// webpackChunkName:Search 用来指明打包后生成的文件名
const Search = () => import(/* webpackChunkName:Search */'@/views/Search')
const User = () => import(/* webpackChunkName:User */'@/views/Layout/User')
const SearchResultList = () => import(/* webpackChunkName:SearchResultList */'@/views/Search/ResultList.vue')
const ArticleDetail = () => import(/* webpackChunkName:ArticleDetail */'@/views/Article/Id.vue')
const UserEdit = () => import(/* webpackChunkName:UserEdit */'@/views/UserEdit')
const Chat = () => import(/* webpackChunkName:Chat */'@/views/Chat')

// import User from '@/views/Layout/User'
// import Search from '@/views/Search'
// import SearchResultList from '@/views/Search/ResultList.vue'
// import ArticleDetail from '@/views/Article/Id.vue'
// import UserEdit from '@/views/UserEdit'
// import Chat from '@/views/Chat'
Vue.use(VueRouter)

const routes = [
  // 重定向
  {
    // 登录
    path: '/login',
    component: Login
  },
  {
    // 首页重定向
    path: '/',
    redirect: '/layout'
  },
  {
    // 首页重定向
    path: '/layout',
    redirect: '/layout/home'
  },
  {
    // 首页
    path: '/layout', // 一级路由
    component: Layout,
    children: [ // 二级路由
      {
        // path: '' 不写相当于在layout
        path: 'home',
        component: Home,
        meta: {
          // 给路由对象添加额外信息
          // 记录当前滚动条的位置
          scrollY: 0
        }
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  {
    // 搜索页
    path: '/search',
    component: Search
  },
  {
    // 搜索结果页
    path: '/search/:keyword', // 动态路由
    component: SearchResultList
  },
  // 文章详情
  {
    // 文章详情
    path: '/article', // 动态路由
    component: ArticleDetail
  },
  {
    // 个人中心编辑页面
    path: '/useredit',
    component: UserEdit
  },
  {
    // 小思同学
    path: '/chat',
    component: Chat
  }
]

const router = new VueRouter({
  routes
})

export default router
